package mode.FlyweighMode11;

import java.util.HashMap;
import java.util.Map;

public class PieceFactory {

    private final Map<String, Piece> map = new HashMap<>();
    public Piece getPiece(String color) {
        Piece piece = map.get(color);
        if (piece == null) {
            switch (color) {
                case "black":
                    piece = new BlackPiece();
                    break;
                case "white":
                    piece = new WhitePiece();
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported color: " + color);
            }
            map.put(color, piece);
        }
        return piece;
    }

}
